% -------------------------------------------------------------------------
% 3 body dynamics
%
% dxx = fx_(t, xx , auxdata)
%
% Input argumuents:
% -------------------------------------------------------------------------
% t                 [1x1 double]          time                 [ TU ]
% xx                [7x1 double]          state variables      [ - ]
% auxdata           [structure]           parameters           [ - ]
%
% Output argumuents:
% -------------------------------------------------------------------------
% dxx               [7x1 double]          vector field         [ - ]
%
% External functions called:
% -------------------------------------------------------------------------
% None
%
% Copyright(C) 2015/06/30 by Chen Zhang,
% School of Astronautics, Beihang University
% chenzhang.buaa@gmail.com
% -------------------------------------------------------------------------

function dxx = fx(t, xx , auxdata)
mu = auxdata.mu;
x = xx(1); y = xx(2); z = xx(3); vx = xx(4); vy = xx(5); vz = xx(6);
r1cube = ((x + mu)^2 + y^2 + z^2)^(3/2);
r2cube = ((x + mu - 1)^2 + y^2 + z^2)^(3/2);
dxx = [vx;
    vy;
    vz;
    x - (1 - mu) * (x + mu) / r1cube - mu * (x + mu - 1) / r2cube + 2*vy;
    y - (1 - mu) * y / r1cube - mu * y / r2cube - 2*vx;
    -(1 - mu) * z / r1cube - mu * z / r2cube];
end
% -------------------------------------------------------------------------
